import allure


# allure动态添加用例的描述封装
def set_allure_metadata(case):
    """
    参数化方式设置allure的元数据
    :param case:
    :return:
    """
    if 'allure' in case:
        allure_data = case['allure']
        if 'story' in allure_data:
            allure.dynamic.story(allure_data['story'])
        if 'title' in allure_data:
            allure.dynamic.title(allure_data['title'])
        if 'description' in allure_data:
            allure.dynamic.description(allure_data['description'])
        if 'severity' in allure_data:
            try:
                severity_level = getattr(allure.severity_level, allure_data['severity'].upper())
                allure.dynamic.severity(severity_level)
            except AttributeError:
                allure.dynamic.severity(allure.severity_level.NORMAL)
